package cn.njyd.corejava.thread.myday05;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

public class CASAtomicIntegerDemo01 {
    private static AtomicInteger count = new AtomicInteger();
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(100);
        for (int i=1;i<=100;i++) {
            new Thread(()->{
                try {
                    for (int j=1;j<=10000;j++) {
                        count.getAndIncrement();
                    }
//                    System.out.println(count);
                } finally {
                  countDownLatch.countDown();
                }
            }).start();
        }
        countDownLatch.await();
        System.out.println("count="+count.get());
    }
}
